package com.gengzp.mq.server.model.generic;

import java.io.Serial;
import java.io.Serializable;

import static com.gengzp.mq.server.constants.MqHttpStatusCodeConstants.FAIL;
import static com.gengzp.mq.server.constants.MqHttpStatusCodeConstants.SUCCESS;

/**
 * @ClassName MqResult
 * @Description mq消息队列内置返回实体
 * @Author gengzp
 * @Date 2025/8/27 16:25
 */
public class MqResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 9070860793493953686L;

    /**
     * 状态码
     */
    private int code;

    /**
     * 状态信息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    private MqResult() {
    }

    public static <T> MqResult<T> success() {
        MqResult<T> result = new MqResult<>();
        result.setCode(SUCCESS);
        result.setMessage("操作成功");
        return result;
    }

    public static <T> MqResult<T> success(T data) {
        MqResult<T> result = new MqResult<>();
        result.setCode(SUCCESS);
        result.setMessage("操作成功");
        result.setData(data);
        return result;
    }

    public static <T> MqResult<T> fail(String message) {
        MqResult<T> result = new MqResult<>();
        result.setCode(FAIL);
        result.setMessage(message);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
